﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace EstudoDirigidoWeb.ConexaoBanco
{

    /// <summary>
    /// Summary description for Conexao
    /// </summary>
    public class Conexao
    {
        public Conexao()
        {

        }

        private SqlConnection conexao;

        public SqlConnection RealizarConexao()
        {
            try
            {
                String strConexao = "Data Source = localhost; Initial Catalog= NorthWind; user= sa; password= senha";
                conexao = new SqlConnection(strConexao);
                conexao.Open();
                return conexao;
            }
            catch (SqlException se)
            {
                Console.WriteLine(se.Message);
                return null;
            }

        }

        public void EncerrarConexao()
        {
            try
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
            catch (SqlException se)
            {
                Console.WriteLine(se.Message);

            }
        }
    }
}